<?php include $this->admin_tpl('meta');?>
<title>添加管理员</title>
</head>
<body>
<article class="page-container">
<div class="formdoby_normal"> 
	<form method="post" onsubmit="return dosub(this)">
	<input type="hidden" name="id" value="<?php echo $data['id'];?>" class="input-text w_300">
	<div class="tabCon formdoby_info" style="display: block;">
		<div class="yzm-table-box">
		<table width="100%" class="table table-border yzmcms_table">
			<tbody>
			<tr>
				<td width="80"><span class="c-red">*</span>店铺名称：</td> 
				<td width="100">
				<input type="text" name="shop_name" autocomplete="off" value="<?php echo $data['shop_name'];?>" class="input-text w_200" placeholder="请输入店铺名称">
				</td>
				<td width="80"><span class="c-red">*</span>管理员：</td>
				<td>
				 <input type="hidden" id="adminids" value="<?php echo $data['adminids'];?>" name="adminids">
				<div class="layui-input-inline" id="admins" style="width:350px;">
				</div>
				</td>
			</tr>
			<tr>
				<td width="80"><span class="c-red">*</span>店铺平台：</td> 
				<td width="100">
					<input type="hidden" name="platform" value="<?php echo $data['platform'];?>" class="input-text">
					<button class="layui-btn layui-btn-primary dropdown-platform" style="height:28px;width:90px;padding:0 10px;">
					<span><?php echo $data['platform_text']??'请选择';?></span>
					<i class="layui-icon layui-icon-down layui-font-12" style="vertical-align: center;"></i>
					</button>
				</td>
				<td width="80"><span class="c-red">*</span>店铺状态：</td>
				<td>
					<input type="hidden" name="shop_status" value="<?php echo $data['shop_status'];?>" class="input-text">
					<button class="layui-btn layui-btn-primary dropdown-status" style="height:28px;width:90px;padding:0 10px;">
					<span><?php echo $data['shop_status_text']??'请选择';?></span>
					<i class="layui-icon layui-icon-down layui-font-12" style="vertical-align: center;"></i>
					</button>
				</td>
			</tr>
			<tr>
				<td width="80"><span class="c-red">*</span>是否自营：</td> 
				<td width="100">
					<span class="span_input">
						<label class="label_radio"><input name="status" type="radio" value="1" <?php if($data['is_own']){?>checked="1"<?php } ?>> 自营</label>
						<label class="label_radio"><input name="status" type="radio" value="0" <?php if(!$data['is_own']){?>checked="1"<?php } ?>> 分销</label>
					</span>
				</td>
				<td width="80">授权截止：</td>
				<td>
					<input type="text" class="input-text laydate-icon" autocomplete="off" value="<?php echo $data['auth_expire'];?>" style="width:175px;height:30px;" name="auth_expire" id="auth_expire" placeholder="yyyy-MM-dd">
				</td>
			</tr>
			<tr>
				<td width="80">备注：</td> 
				<td colspan="3">
				<input type="text" name="remark" value="<?php echo $data['remark'];?>" autocomplete="off" class="input-text" placeholder="备注">
				</td>
			</tr>

				<tr>
					<td width="80">公司名称：</td> 
					<td width="120">
						<input type="text" name="other[company_name]" value="<?php echo $data['other']['company_name'];?>" class="input-text w_200" autocomplete="off" placeholder="请输入公司名称">
					</td>
					<td width="80">公司简称：</td>
					<td>
						<input type="text" name="other[company_short_name]" value="<?php echo $data['other']['company_short_name'];?>" class="input-text w_200" autocomplete="off" placeholder="请输入公司简称">
					</td>
				</tr>
				<tr>
					<td width="80">法人姓名：</td> 
					<td width="120">
						<input type="text" name="other[legal_person]" value="<?php echo $data['other']['legal_person'];?>" class="input-text w_200" autocomplete="off" placeholder="请输入法人姓名">
					</td>
					<td width="80">电话号码：</td>
					<td>
						<input type="text" name="other[mobile]" value="<?php echo $data['other']['mobile'];?>" class="input-text w_200" autocomplete="off" placeholder="请输入电话号码">
					</td>
				</tr>
				<tr>
					<td width="80">开店押金：</td> 
					<td width="120">
						<input type="text" name="other[deposit_price]" value="<?php echo $data['other']['deposit_price'];?>" class="input-text w_200" autocomplete="off" placeholder="请输入开店押金">
					</td>
					<td width="80">开店费用：</td>
					<td>
						<input type="text" name="other[open_price]" value="<?php echo $data['other']['open_price'];?>" class="input-text w_200" autocomplete="off" placeholder="请输入开店费用">
					</td>
				</tr>
				<tr>
					<td width="80">收款渠道：</td> 
					<td width="120">
						<input type="text" name="other[price_source]" value="<?php echo $data['other']['price_source'];?>" class="input-text w_200" autocomplete="off" placeholder="请输入收款渠道">
					</td>
					<td width="80">收款日期：</td>
					<td>
						<input type="text" name="other[price_time]" value="<?php echo $data['other']['price_time'];?>" class="input-text w_200" id="price_time" autocomplete="off" placeholder="yyyy-MM-dd">
					</td>
				</tr>
			</tbody>
		</table>
		</div>
	
	</div>
	<div class="footer_btn">
		<input type="hidden" name="dosubmit" value="1">
		<input class="btn btn-primary radius" type="submit" value="提 交">
		<input class="btn btn-default radius" type="button" value="取 消" onclick="yzmcms_close()">	
	</div>
	</form>
</div>
</article>
<?php include $this->admin_tpl('footer');?>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/layui/layui.js"></script>
<script type="text/javascript" src="<?php echo STATIC_URL;?>plugin/layui/modules/xm-select.js"></script>
<script type="text/javascript">
layui.use(function(){
	dropdown = layui.dropdown; //下拉菜单
	laydate = layui.laydate;
	laydate.render({
		elem: '#auth_expire'
	});
	laydate.render({
		elem: '#price_time'
	});
	dropdown.render({
		elem: '.dropdown-platform',
		// trigger: 'hover',
		// 此处的 data 值，可根据 done 返回的 res 遍历来赋值
		data: <?php echo json_encode($platform_arr);?>,
		click: function(obj){
			$('input[name="platform"]').val(obj.id);
			this.elem.find('span').html(obj.title);
		}
	});

	dropdown.render({
		elem: '.dropdown-status',
		// trigger: 'hover',
		// 此处的 data 值，可根据 done 返回的 res 遍历来赋值
		data: <?php echo json_encode($shop_status_arr);?>,
		click: function(obj){
			$('input[name="shop_status"]').val(obj.id);
			this.elem.find('span').html(obj.title);
		}
	});
	
    // 创建一个下拉选择框，并设置相关属性
    var admins = xmSelect.render({
        el: '#admins', // 将下拉选择框挂载到id为category的元素上
        toolbar: {//开启单选则不需要头部工具栏
            show: false, // 显示工具栏
            list: [ 'ALL', 'CLEAR'] // 工具栏上的选项列表
        },
        theme: {
            color: '#409eff', // 设置主题颜色
        },
        filterable: true, // 允许筛选
        paging: true, // 启用分页
        // radio: true,//单选
        pageSize: 10,
        on: function (data) {
            //arr:  当前多选已选中的数据
            var arr = data.arr;
			var items = [];
			arr.map(function (item) {
                items.push(item.value);
            });
            // 从选中数据中提取value值
            var value = items.join(',');
            // 存储所选数据的值,这里是在前端隐藏了书籍类别输入框，将提出出来的值写入到表单中便于提交到数据库中
            $('#adminids').val(value);//这里是将我自己需要的值返回到前端界面，再提交表单的时候不需要将数据转化，当然你也可以自己摸索一下

        },
        data: [],
    })
    // 发送一个GET请求，从后端获取所有分类信息
    $.ajax({
        url: '<?php echo U('get_admin');?>', // 请求的URL
		dataType: "json", 
        type: 'GET', // 请求类型为GET
        success: function (data) { // 请求成功后执行的回调函数
            var newData = data.map(function (item) {
                return {name: item.adminname, value: item.adminid};
            });
            // 更新下拉选择框的数据
            admins.update({data: newData});
			admins.setValue([<?php echo $data['adminids'];?>]);
        }, error: function (error) { // 请求失败后执行的回调函数
            console.log('Error fetching data from backend: ' + error); // 在控制台输出错误信息
        }
    })

	
})




function dosub(obj){
	if(obj.shop_name.value==''){
		layer.msg('公司名称！', {icon:2});
		return false;
	}
	$.ajax({
		type: 'POST',
		url: '<?php echo U('collect_shop',['type'=>'add']);?>', 
		data: $(obj).serialize(),
		dataType: "json", 
		success: function (msg) {
			if(msg.status == 1){
				layer.msg(msg.message, {icon:1, time:800}, function(){
					parent.table.reload('table');
					var index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
					parent.layer.close(index); // 再执行关闭
				});
			}else{
				layer.msg(msg.message, {icon:2});
			}
		}
	})		 
	return false;			 
}
</script> 

</body>
</html>